<?php
defined('BY_JYA') or exit('error');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$return['morefeelog_status']=$this->morefeelog_status;
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if($_RQ['title']){
		$params2=array('uniacid'=>$_SESSION['uniacid']);
		$params2['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
		$workerid=pdo_getall('jy_shopworker_list',$params2,array('title','id'),'id');
		if($workerid){
			$workerid=array_keys($workerid);
		}else{
			$workerid=-1;
		}
		$params['workerid']=$workerid;
	}
	if($_RQ['id']){
		$params['workerid']=$_RQ['id'];
		$return['params']['id']=$_RQ['id'];
	}
	if($_RQ['cname']){
		$params['cname like']='%'.trim($_RQ['cname']).'%';
		$return['params']['cname']=$_RQ['cname'];
	}
	if($_RQ['mobile']){
		$params['mobile like']='%'.trim($_RQ['mobile']).'%';
		$return['params']['mobile']=$_RQ['mobile'];
	}
	if($_RQ['username']){
		$params['username like']='%'.trim($_RQ['username']).'%';
		$return['params']['username']=$_RQ['username'];
	}
	if($_RQ['status']){
		$params['status']=$_RQ['status'];
		$return['params']['status']=$_RQ['status'];
	}
	if(!empty($_RQ['y']) && !empty($_RQ['m'])){
		$yuestart = mktime(0,0,0,$_RQ['m'],1,$_RQ['y']);
		$yueend = mktime(0,0,0,$_RQ['m']+1,1,$_RQ['y']);
		$params['pay_time between']=array($yuestart,$yueend);
	}elseif(!empty($_RQ['y'])){
		$yuestart = mktime(0,0,0,1,1,$_RQ['y']);
		$yueend = mktime(0,0,0,1,1,$_RQ['y']+1);
		$params['pay_time between']=array($yuestart,$yueend);
	}
	if(!empty($_RQ['y'])){
		$return['params']['y']=$_RQ['y'];
	}
	if(!empty($_RQ['m'])){
		$return['params']['m']=$_RQ['m'];
	}
	$orderby=array();
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_shopworker_morefeelog',$params,array($pindex,$psize),$total,$fields,'','id desc');
	foreach($list as &$item){
	}
	$return['list']=$list?$list:array();
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'其他费用列表'),
		),
		'list'=>array('data'=>'list','edit'=>false,'list'=>array(
			array('name'=>'workerid','title'=>'员工','type'=>'select','options'=>'workers'),
			array('name'=>'price','title'=>'额度','type'=>'string'),
			array('name'=>'remark','title'=>'费用说明','type'=>'string'),
			array('name'=>'isadd','title'=>'费用类型','type'=>'radio','options'=>'isadd'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'morefeelog_status'),
			array('name'=>'upworkerid','title'=>'审批人','type'=>'select','options'=>'workers'),
			array('name'=>'month','title'=>'月份','type'=>'string'),
			array('name'=>'createtime','title'=>'创建时间','type'=>'time'),
		),'action'=>array(
			array('type'=>'modal','action'=>'jy_shopworker/morefeelog/chgange','title'=>'修改费用'),
		)),
		'search'=>array(
			array('type'=>'string','width'=>'10','title'=>'员工姓名','name'=>'title','help'=>''),
			array('name'=>'y','width'=>10,'title'=>'年份','type'=>'radio','options'=>'ys'),
			array('name'=>'m','width'=>10,'title'=>'月份','type'=>'radio','options'=>'months'),
		),
	);
	$return['workers']=pdo_getall('jy_shopworker_list',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	$return['isadd']=array('扣除','增加');
	$nowy=date('Y');
	$y1=$nowy-2;
	$y2=$nowy-1;
	$return['ys']=array(
		$y1=>$y1.'年',
		$y2=>$y2.'年',
		$nowy=>$nowy.'年',
	);
	$return['months']=array(
		'01'=>'1月',
		'02'=>'2月',
		'03'=>'3月',
		'04'=>'4月',
		'05'=>'5月',
		'06'=>'6月',
		'07'=>'7月',
		'08'=>'8月',
		'09'=>'9月',
		'10'=>'10月',
		'11'=>'11月',
		'12'=>'12月',
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='chgange'){
	if($_RQ['postdata']){
		$postdata=get_postdata();
		$data=array(
			'price'=>trim($postdata['price']),
		);
		$id=intval($postdata['id']);
		if($id){
			pdo_update('jy_shopworker_morefeelog',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
			exi('处理成功！','','list');
		}else{
			exi('没有找到审批');
	}
	}
	$id=intval($_RQ['id']);
	$item=pdo_get('jy_shopworker_morefeelog',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	$return['item']=$item;
	$return['htmls']=array(
			'type'=>'edit',
			'edit'=>array(
				array('name'=>'price','title'=>'额度','type'=>'string'),
			),
	);
	exi($return);
}
if($_RQ['op']=='del'){
	$id=intval($_RQ['id']);
	if($id){
		pdo_delete('jy_shopworker_morefeelog',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				pdo_delete('jy_shopworker_morefeelog',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
			}
		}
	}
	exi('删除成功！');
}